<template>
    <div class="account-tidings">
        <c-wrap title="参数设置">
            <p class="mint-radiolist-title" style="text-align: left">消息设置</p>
            <mt-cell title="关于我的">
                <mt-switch v-model="user.message" @change="change"></mt-switch>
            </mt-cell>
            <mt-cell title="全局公告">
                <mt-switch v-model="user.notice" @change="change"></mt-switch>
            </mt-cell>
            <p class="mint-radiolist-title" style="text-align: left">扣费设置</p>
            <mt-cell title="自动扣费">
                <mt-switch v-model="user.autoPay" @change="change"></mt-switch>
            </mt-cell>
        </c-wrap>
    </div>
</template>
<script>
    import CWrap from '../../components/CWrap'

    export default {
        components: {CWrap},
        data() {
            return {
                user: {
                    message: false,
                    notice: false,
                    autoPay: false
                }
            }
        },
        methods: {
            loadData() {
                app.ajax.get(app.config.api.account.setting, {}, (res) => {
                    if (res.data) {
                        this.user.message = Boolean(res.data.message);      //0是开
                        this.user.notice = Boolean(res.data.notice);
                        this.user.autoPay = Boolean(res.data.autoPay);
                    }
                });
            },
            change() {
                app.ajax.put(app.config.api.account.setting, {
                    message: Number(this.user.message),
                    notice: Number(this.user.notice),
                    autoPay: Number(this.user.autoPay)
                });
            }
        },
        mounted() {
            this.loadData();
        }
    }
</script>
